const router = require('koa-router')()
const formidable = require("formidable")

router.get('/', async ctx => {
    ctx.body = 'Hello world'
})

router.post('/form-data', async ctx => {
    let form = new formidable.IncomingForm()
    await new Promise((resolve, reject) => {
        form.parse(ctx.req, (error, fields, files) => {
            if (error) {
                throw error
                return reject()
            }
            ctx.body = JSON.stringify(fields)
            resolve(fields)
        })
    })
})

module.exports = router